/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HighscoreWindow.java
 *
 * Created on 4-mrt-2012, 8:43:59
 */

package sokoban.view;

import java.util.*;
import sokoban.model.Highscore;
import javax.swing.table.DefaultTableModel;
/**
 *
 * @author Admin
 */
public class HighscoreWindow extends javax.swing.JFrame {
    private HashMap highscores;

    /** Creates new form HighscoreWindow */
    public HighscoreWindow() {
        initComponents();
    }

    public HighscoreWindow(HashMap<Integer, Highscore> highscores)
    {
        initComponents();

        this.highscores = highscores;

        // Sorteer de hashmap op sleutel (level)
        SortedSet<Integer> sortedset= new TreeSet<Integer>(this.highscores.keySet());
        Iterator<Integer> it = sortedset.iterator();

        DefaultTableModel mdlZonderKindmodus = new DefaultTableModel();
        DefaultTableModel mdlMetKindmodus = new DefaultTableModel();

        tblZonderKindmodus.setModel(mdlZonderKindmodus);
        tblMetKindmodus.setModel(mdlMetKindmodus);

        mdlZonderKindmodus.addColumn("Level");
        mdlZonderKindmodus.addColumn("Score");
        mdlZonderKindmodus.addColumn("Naam");

        mdlMetKindmodus.addColumn("Level");
        mdlMetKindmodus.addColumn("Score");
        mdlMetKindmodus.addColumn("Naam");

        while (it.hasNext()) {
            Highscore highscore = (Highscore)this.highscores.get(it.next());
            
            if (highscore.getLevel() <= 12){
                mdlZonderKindmodus.addRow(new Object[]{highscore.getLevel(), highscore.getScore(), highscore.getNaam()});
            }else{
                mdlMetKindmodus.addRow(new Object[]{(highscore.getLevel()-12), highscore.getScore(), highscore.getNaam()});
            }
        }    
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tblZonderKindmodus = new javax.swing.JTable();
        highscoreExitBtn = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblMetKindmodus = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        tblZonderKindmodus.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Spel", "Score", "Naam"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Integer.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblZonderKindmodus);
        tblZonderKindmodus.getColumnModel().getColumn(0).setPreferredWidth(20);
        tblZonderKindmodus.getColumnModel().getColumn(1).setPreferredWidth(20);

        highscoreExitBtn.setText("Sluiten");
        highscoreExitBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                highscoreExitBtnActionPerformed(evt);
            }
        });

        jLabel1.setText("Zonder kindmodus");

        jLabel2.setText("Met kindmodus");

        tblMetKindmodus.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Spel", "Score", "Naam"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Integer.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(tblMetKindmodus);
        tblMetKindmodus.getColumnModel().getColumn(0).setPreferredWidth(20);
        tblMetKindmodus.getColumnModel().getColumn(1).setPreferredWidth(20);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(highscoreExitBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(highscoreExitBtn)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void highscoreExitBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_highscoreExitBtnActionPerformed
        dispose();
    }//GEN-LAST:event_highscoreExitBtnActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new HighscoreWindow().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton highscoreExitBtn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable tblMetKindmodus;
    private javax.swing.JTable tblZonderKindmodus;
    // End of variables declaration//GEN-END:variables

}
